﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using WFNetLib;
using WFNetLib.Net;
using HtmlAgilityPack;


namespace 移动支付
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Cookies = new CookieCollection();
            r = new Random();
        }
        CookieCollection Cookies;
        Random r;
        string token;
        System.IO.StreamReader Reader;
        private void button1_Click(object sender, EventArgs e)
        {
            HttpWebResponse re = WFHttpWebResponse.CreateGetHttpResponse("https://cmpay.10086.cn/", null, null, null);
            //System.IO.StreamReader Reader = new System.IO.StreamReader(re.GetResponseStream(), System.Text.Encoding.GetEncoding(re.CharacterSet));
            //CookieCollection coos = HttpStatic.GetCookies(re.Headers["Set-Cookie"]);
//             foreach (string str in re.Headers["Set-Cookie"].Split)
//             {
//             }
//              
//             Cookie coo=new Cookie()
            //textBox1.Text = Reader.ReadToEnd();
            foreach (Cookie c in re.Cookies)
            {
                if (Cookies[c.Name] != null)
                    Cookies[c.Name].Value = c.Value;
                else
                    Cookies.Add(c);
            }
            re.Close();
            re = WFHttpWebResponse.CreateGetHttpResponse("https://cmpay.10086.cn/service/register.xhtml?WT.ad_id=indexLoginzhuce", null, null, Cookies);
            foreach (Cookie c in re.Cookies)
            {
                if (Cookies[c.Name] != null)
                    Cookies[c.Name].Value = c.Value;
                else
                    Cookies.Add(c);
            }
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            Reader = new System.IO.StreamReader(re.GetResponseStream(), System.Text.Encoding.GetEncoding(re.CharacterSet));
            
            //textBox1.Text = re.Headers["Set-Cookie"];
            //textBox1.AppendText("\r\n\r\n\r\n\r\n");
            textBox1.Text=Reader.ReadToEnd();
            doc.LoadHtml(textBox1.Text);
            HtmlNode navNode = doc.GetElementbyId("token");
            token=navNode.Attributes["value"].Value.ToString();

            Reader.Close();
            re.Close();
            IDictionary<string, string> HeaderParameters = new Dictionary<string, string>();
            HeaderParameters.Add("x-requested-with", "XMLHttpRequest");
            re = WFHttpWebResponse.CreateGetHttpResponse("https://cmpay.10086.cn/service/send_chk_no.xhtml?REG_MBL_NO=18746128628&SMS_CD=URM001&typ=Y&r=" + r.NextDouble().ToString("F16"), null, null, Cookies);
            foreach (Cookie c in re.Cookies)
            {
                if (Cookies[c.Name] != null)
                    Cookies[c.Name].Value = c.Value;
                else
                    Cookies.Add(c);
            }
            Reader = new System.IO.StreamReader(re.GetResponseStream(), System.Text.Encoding.GetEncoding(re.CharacterSet));
            //发送短信间隔时间需大于3分钟
            //对不起，此用户已存在
            //对不起，您尚未开通手机支付账户
            
            Reader.Close();
            re.Close();
           
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            string url = "https://cmpay.10086.cn/service/register_first.xhtml?token=";
            url += token;
            url += "&REG_MBL_NO=18746128628&EMAIL=F&FEINO=F&CHK_NO=";
            url += toolStripTextBox1.Text;
            url += "&agree_flg=1";
            HttpWebResponse re = WFHttpWebResponse.CreateGetHttpResponse(url, null, null, Cookies);
            Reader = new System.IO.StreamReader(re.GetResponseStream(), System.Text.Encoding.GetEncoding(re.CharacterSet));
            //发送短信间隔时间需大于3分钟
            //对不起，此用户已存在
            //对不起，您尚未开通手机支付账户
            textBox1.Text = re.Headers["Set-Cookie"];
            textBox1.AppendText("\r\n\r\n\r\n\r\n");
            textBox1.AppendText(Reader.ReadToEnd());
            Reader.Close();
            re.Close();
            url = "https://cmpay.10086.cn/service/register_second.xhtml?token=";
            url += token;
            url += "&PSW_LVL=2&REG_MBL_NO=18746128628&REG_USR_OPR_LOG_ID=1878628111&GOTO_FLG=&LOG_PSWD=m3zYEjPIzPuqdQ6nre2TViTUntifOPnj7ChjY63FeHp0XIzMiIwsO2BCvo8na6KRrotEFqs6DFVtXvQJd0cV%2Bph1OFdswF5xVANZDbhZ5j6FOibLZ5xb8tmWzi67u7WoqBuEAo8tqNJnJZNfmItjvJ4VzAFcM7YU5kfD5b%2BAAavuNYW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DmYQ6hsxNTNpXWHUGWRa1CTBc7CDj52ZxbTAl1xollE0708%2FNpR6f8WxMwHqlUfFFUsl7UEp1wi3nvOjJqCIRRYhYiBtwGU5yHsp6tMlh2BlUqAL6Xe%2FZnmWnqHvmiiuJ7wZJQF%2BuMcTQuWDmAseJJdYRkUGevZ5r1kjx49HCxexCrz4AuoI4sK1dpEodEWhMJd4MocwhDzBd%2F7WQjrGCbQzTInVHLhrb40VgU2apxMETzQ3pnQeJ%2FP%2BVNmoDvKXfkTvJ4YaxIeLoAs7p4duGKuDTDhCvHzCKrc%3D&answerSel=%CE%D2%B8%B8%C7%D7%B5%C4%B3%F6%C9%FA%B5%D8&QUES1=%CE%D2%B8%B8%C7%D7%B5%C4%B3%F6%C9%FA%B5%D8&ANS1=%B9%FE%B6%FB%B1%F5";
            re = WFHttpWebResponse.CreateGetHttpResponse(url, null, null, Cookies);
            Reader = new System.IO.StreamReader(re.GetResponseStream(), System.Text.Encoding.GetEncoding(re.CharacterSet));
            //发送短信间隔时间需大于3分钟
            //对不起，此用户已存在
            //对不起，您尚未开通手机支付账户
            textBox1.Text = re.Headers["Set-Cookie"];
            textBox1.AppendText("\r\n\r\n\r\n\r\n");
            textBox1.AppendText(Reader.ReadToEnd());
            Reader.Close();
            re.Close();
        }
    }
}
